Column

Distribution of Order Hour of Day for Each Department

Column

Total Number of Items of Each Department

Fluctuation of Number of Orders Among the Day

---
title: "Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source_code: embed
---

```{r setup, include=FALSE}
library(tidyverse)
library(plotly)
library(p8105.datasets)
library(flexdashboard)
data("instacart")

library(p8105.datasets)

theme_set(theme_minimal() + theme(legend.position = "right"))

options(
  ggplot2.continuous.colour = "viridis",
  ggplot2.continuous.fill = "viridis"
)

scale_colour_discrete = scale_colour_viridis_d
scale_fill_discrete = scale_fill_viridis_d
```

```{r}
data(instacart)
instacart_df = 
  instacart |> 
  select(
    order_id, product_id, order_number, order_hour_of_day, product_name, aisle, department, department_id
  )

```



Column {data-width=650}
-----------------------------------------------------------------------

### Distribution of Order Hour of Day for Each Department

```{r}
instacart_df |> 
  group_by(department) |> 
  plot_ly(x = ~department, y = ~order_hour_of_day, color = ~department,
          type = "box", colors = "viridis")
```

Column {data-width=350}
-----------------------------------------------------------------------

### Total Number of Items of Each Department

```{r}
instacart_df |> 
  count(department) |>
  mutate(department = fct_reorder(department, n)) |> 
  plot_ly( x=~department, y=~n, color = ~department,
           type = "bar", colors = "viridis")
```

### Fluctuation of Number of Orders Among the Day

```{r}
instacart_df |> 
  group_by(order_hour_of_day)|> 
  summarise(n_order = n_distinct(order_id))|> 
  plot_ly(x = ~order_hour_of_day, y = ~n_order, type = 'scatter', mode = 'lines')
```